<!DOCTYPE html>
<html>
<head>
    <title>测试前端与后端通信</title>
</head>
<body>
    <h1>测试前端与后端通信</h1>
    <button onclick="testLogin()">测试登录API</button>
    <div id="result"></div>

    <script>
        async function testLogin() {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = '正在测试...';
            
            try {
                const response = await fetch('http://localhost:3000/api/users/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'Origin': 'http://127.0.0.1:5174'
                    },
                    body: JSON.stringify({
                        email: 'test@example.com',
                        password: 'password123'
                    })
                });
                
                const data = await response.json();
                resultDiv.innerHTML = `状态: ${response.status}<br>数据: ${JSON.stringify(data)}`;
            } catch (error) {
                resultDiv.innerHTML = `错误: ${error.message}`;
            }
        }
    </script>
</body>
</html>